{ "cells": [ { "cell_type": "markdown", "id": "4eb1ee6b-58d5-4f68-8c56-645b4ce23705", "metadata": {}, "source": [ "# pyopenms" ] }, { "cell_type": "raw", "id": "7b7f7b40-9948-4035-9d1e-6013e327d49f", "metadata": { "editable": true, "raw_mimetype": "text/html", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "\n", " \"Launch\n", "\n", "

" ] }, { "cell_type": "markdown", "id": "67055e7c-e4e2-4648-8df6-ea04f17e1809", "metadata": {}, "source": [ "## Install pyopenms" ] }, { "cell_type": "code", "execution_count": 3, "id": "70b62198-0dba-4573-8dbe-19f31a10c7f4", "metadata": {}, "outputs": [], "source": [ "!pip install pyopenms --quiet" ] }, { "cell_type": "code", "execution_count": 4, "id": "0c68afe3-cd59-424a-b822-46ffca16456a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "File test.mzML downloaded successfully!\n" ] } ], "source": [ "import requests\n", "\n", "url = 'https://raw.githubusercontent.com/levitsky/pyteomics/master/tests/test.mzML'\n", "file_name = 'test.mzML'\n", "\n", "# # Send a GET request to the URL\n", "response = requests.get(url)\n", "\n", "# # Save the content of the response to a file\n", "with open(file_name, 'wb') as file:\n", " file.write(response.content)\n", "\n", "print(f'File {file_name} downloaded successfully!')" ] }, { "cell_type": "markdown", "id": "53eabf53-784c-4147-b589-e989ed17f9a3", "metadata": {}, "source": [ "## Load `.mzML` file and convert to `pd.DataFrame`" ] }, { "cell_type": "code", "execution_count": 8, "id": "61f85915-0450-499d-a451-38c6d26b4315", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
RTmzinty
00.2961200.0001830.0
10.2961200.0004270.0
20.2961200.0006710.0
30.2961200.0009160.0
40.2961202.6058350.0
............
398230.35611999.9130860.0
398240.35611999.9372560.0
398250.35611999.9615480.0
398260.35611999.9857180.0
398270.35612000.0098880.0
\n", "

39828 rows × 3 columns

\n", "
" ], "text/plain": [ " RT mz inty\n", "0 0.2961 200.000183 0.0\n", "1 0.2961 200.000427 0.0\n", "2 0.2961 200.000671 0.0\n", "3 0.2961 200.000916 0.0\n", "4 0.2961 202.605835 0.0\n", "... ... ... ...\n", "39823 0.3561 1999.913086 0.0\n", "39824 0.3561 1999.937256 0.0\n", "39825 0.3561 1999.961548 0.0\n", "39826 0.3561 1999.985718 0.0\n", "39827 0.3561 2000.009888 0.0\n", "\n", "[39828 rows x 3 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pyopenms as oms\n", "input_file = \"./test.mzML\"\n", "\n", "# open mzML file\n", "exp = oms.MSExperiment()\n", "oms.MzMLFile().load(input_file, exp)\n", "\n", "# convert to pd.DataFrame\n", "df = exp.get_df(long=True)\n", "df" ] }, { "cell_type": "markdown", "id": "7955e0ff-25f4-4de8-8f88-0170ebe0167f", "metadata": {}, "source": [ "## Convert a single Spectrum as a `pd.DataFrame`" ] }, { "cell_type": "markdown", "id": "d7b560a0-5135-4c05-952f-3b6083802595", "metadata": {}, "source": [ "This can be achieved by filtering the dataframe above to the desired spectrum or can be done with the pyopenms interface. " ] }, { "cell_type": "code", "execution_count": 12, "id": "c1c7d799-8bad-4075-86c4-20689ea15259", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
mzintensityion_mobilityion_mobility_unitms_levelprecursor_mzprecursor_chargenative_idsequenceion_annotationbase peak m/zbase peak intensitytotal ion currentlowest observed m/zhighest observed m/zfilter stringpreset scan configuration
0200.0001880.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
1200.0004300.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
2200.0006730.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
3200.0009150.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
4202.6058290.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
......................................................
199091999.9130810.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
199101999.9372960.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
199111999.9615130.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
199121999.9857290.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
199132000.0099470.0NaN<NONE>10.00controllerType=0 controllerNumber=1 scan=18101471973152450682002000FTMS + p ESI Full ms [200.00-2000.00]1
\n", "

19914 rows × 17 columns

\n", "
" ], "text/plain": [ " mz ... preset scan configuration\n", "0 200.000188 ... 1\n", "1 200.000430 ... 1\n", "2 200.000673 ... 1\n", "3 200.000915 ... 1\n", "4 202.605829 ... 1\n", "... ... ... ...\n", "19909 1999.913081 ... 1\n", "19910 1999.937296 ... 1\n", "19911 1999.961513 ... 1\n", "19912 1999.985729 ... 1\n", "19913 2000.009947 ... 1\n", "\n", "[19914 rows x 17 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "spectrum = oms.MSSpectrum(exp.getSpectrum(0))\n", "df = spectrum.get_df()\n", "df" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.7" } }, "nbformat": 4, "nbformat_minor": 5 }